package net.alteiar.ui.editor.tools;

import java.awt.Color;
import java.awt.Point;

import net.alteiar.images.metadata.ImageInfo;

public class Brush extends ImageInfoTool {

	private int size;
	private int value;

	public Brush(ImageInfo info, ImageInfo tmp) {
		super(info, tmp);

		size = 50;
		value = Color.BLACK.getRGB();
	}

	public int getValue() {
		return value;
	}

	public void setValue(int value) {
		this.value = value;
	}

	public int getSize() {
		return size;
	}

	public void setSize(int size) {
		this.size = size;
	}

	@Override
	public void doAction(ImageInfo info, Point imgPos) {
		int halfSize = size / 2;
		int width = info.getWidthSquare() * info.getSquareSize();
		int height = info.getHeightSquare() * info.getSquareSize();
		int x = Math.min(width - halfSize, Math.max(0, imgPos.x - halfSize));
		int y = Math.min(height - halfSize, Math.max(0, imgPos.y - halfSize));

		info.setValueAt(x, y, size, size, value);
	}
}
